﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Brouteforce.Map {
    static class Tile {
        static public Texture2D TileSetTexture;
        static public Texture2D CastleTexture;
        
        static public int TileWidth = 64;
        static public int TileHeight = 64;
        static public int TileStepX = 64;
        static public int TileStepY = 16;
        static public int OddRowXOffset = 32;
        static public int HeightTileOffset = 32;
        public static KeyValuePair<Texture2D, Rectangle>[] Textures;

        static public Vector2 originPoint = new Vector2(19, 39);

        static public Rectangle GetSourceRectangle(int tileIndex) {
            int tileY = tileIndex / (TileSetTexture.Width / TileWidth);
            int tileX = tileIndex % (TileSetTexture.Width / TileWidth);

            return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight);
        }

        public static void CutContent()
        {
            Textures = new KeyValuePair<Texture2D, Rectangle>[100];
            int i = 1;
            //Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 0, 64, 64));
            var s = -25;
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 0 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 32 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 64 + s, 64, 64));
            Textures[i++] = new KeyValuePair<Texture2D, Rectangle>(CastleTexture, new Rectangle(0, 96 + s, 64, 64));
        }
    }
}
